<div class="layui-form-item">
    <label class="layui-form-label" >{:lang('Coordinate')}</label>
    <div class="layui-input-6">
        <input type="text"  id="_location" name="location" value="{$row['location']}" lay-verify="required" placeholder="{:lang('Please input coordinates')}" readonly="" class="layui-input">
        <div style="width: 100%;margin-top: 10px;"> 
            <p id="allmap" style="width: 500px;height: 400px;"></p>
        </div>
    </div>
    
</div>
<?php if($lang=='en-us'):?>
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDe-cyaBixq_YRSFN2GFILKee5zWrkj1dQ&sensor=false"></script>
    <script>
    var myLatlng = {
        lat: 51.50874,
        lng: -0.120850
    };
    var marker=null;
    var markersArray = [];
function initialize()
{
    if($("#_location").val() != null && $("#_location").val() != ''){
        var p = $("#_location").val().split(",");
        myLatlng = {lng:parseFloat(p[0]),lat:parseFloat(p[1])};
    }
    var mapProp = {
        center:new google.maps.LatLng(myLatlng),
        zoom:7,
        mapTypeId:google.maps.MapTypeId.ROADMAP
    };
    var map=new google.maps.Map(document.getElementById("allmap"), mapProp);
    // Zoom to 9 when clicking on marker
    addMarker(myLatlng, map);
    map.addListener('click', function (e) {
        addMarker(e.latLng, map);
        var latLngData = e.latLng.lng().toFixed(6) + ',' + e.latLng.lat().toFixed(6);
        $("#_location").val(latLngData)
    })
}
 //添加坐标对象
function addMarker(latLng, map) {
    if (markersArray.length > 0) {
        markersArray[0].setMap(null);
    }
    ;
    markersArray.shift(marker)
    marker = new google.maps.Marker({
        position: latLng,
        map: map
    });
    markersArray.push(marker);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<?php else:?>
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=zu9DVQ4e21BwI7DAAr0uNYp6k4ZrWVP8"></script>
<script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("allmap");    // 创建Map实例
    if($("#_location").val() != null && $("#_location").val() != ''){
         var p = $("#_location").val().split(",");
        map.centerAndZoom(new BMap.Point(p[0],p[1]), 5);  // 初始化地图,设置中心点坐标和地图级别
    }else{
        map.centerAndZoom(new BMap.Point(116.404, 39.915), 5);  // 初始化地图,设置中心点坐标和地图级别
    }
    
    //添加地图类型控件
    map.addControl(new BMap.MapTypeControl({
        mapTypes:[
            BMAP_NORMAL_MAP,
            BMAP_HYBRID_MAP
        ]}));     
    //map.setCurrentCity("北京");          // 设置地图显示的城市 此项是必须设置的
    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
    var marker = null;
    function showInfo(e){

        //layer.msg("{:lang('Current coordinates:')}"+e.point.lng + ", " + e.point.lat)
        var point = new BMap.Point(e.point.lng,e.point.lat);
        if(marker != null){
            marker.remove();
        }
        marker = new BMap.Marker(point);  // 创建标注
        map.removeOverlay(marker);
        map.addOverlay(marker);              // 将标注添加到地图中
        $("#_location").val(e.point.lng + ", " + e.point.lat);
    }
    if($("#_location").val() != null && $("#_location").val() != ''){
        var p = $("#_location").val().split(",");
        var point = new BMap.Point(p[0],p[1]);
         marker = new BMap.Marker(point);  // 创建标注
         map.addOverlay(marker);              // 将标注添加到地图中
    }
    map.addEventListener("click", showInfo);
</script>
<?php endif;?>